import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/route_manager.dart';
import 'package:razer_one/app/main/utils/alert_utils.dart';
import 'package:razer_one/app/main/utils/sizefit_util.dart';
import 'package:razer_one/app/routes/app_pages.dart';
import 'package:razer_one/app/routes/app_routes.dart';
import 'package:razer_one/app/theme/app_theme.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  StreamSubscription<ConnectivityResult>? _connectivitySubscription;

  @override
  void initState() {
    super.initState();
    // networkConfig();
  }

  @override
  void dispose() {
    super.dispose();
    _connectivitySubscription?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    //初始化适配信息
    AppSizeFit.initialize();

    return GetMaterialApp(
      //去掉右上角debug
      debugShowCheckedModeBanner: false,
      title: "razer",
      //主题
      theme: AppTheme.norTheme,
      //路由
      initialRoute: AppRoutes.launchRoute,
      getPages: AppPages.pages,
      builder: EasyLoading.init(),
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate, // 指定本地化的字符串和一些其他的值
        GlobalCupertinoLocalizations.delegate, // 对应的Cupertino风格
        GlobalWidgetsLocalizations.delegate // 指定默认的文本排列方向, 由左到右或由右到左
      ],

      // navigatorKey: Get.key,
      locale: const Locale("zh", "CH"),
      supportedLocales: const [Locale("en"), Locale("zh")],
    );
  }

  //网络初始状态
  networkConfig() {
    _connectivitySubscription = Connectivity()
        .onConnectivityChanged
        .listen((ConnectivityResult result) {
      if (result == ConnectivityResult.none) {
        AlertUtils.show("'网络已断开,请检查网络!");
      } else {}
    });
  }
}
